The present invention generally relates to threads of computer program execution, and more particularly, to use and reuse of a thread for different programmed operations.
A thread is commonly viewed as a light-weight flow of control within a process, wherein a process is a heavy-weight flow of control. A process is heavy-weight in that the operating system allocates a dedicated memory domain for program code and data used by the process, whereas a thread is lightweight in that a thread exists within the memory domain of a process. Some processes are multithreaded such that multiple threads can execute concurrently within a process.
Threads are generally created with support from an operating system and are commonly executed by coupling the thread with a specific operation. That is, a thread is created for the purpose of performing a specific operation. After the operation is complete, the thread may be destroyed or reused in performing the same operation with perhaps different input data.
Creating and initiating new threads can be expensive in terms of consuming operating system resources. Each time a new thread is required, control must be passed to the operating system in order to create the thread, and establish and create any structures required to manage the thread. Thus, some applications create multiple threads for performing the same operation within a process. However, the threads are dedicated to the specific operations for which they were created, which may be inefficient for resource utilization. For example, a first set of threads may be created and dedicated to a first function of a system, and a second set of threads may be created and dedicated to a second function of the system. If demand for the first function is low, wherein only a few of the first set of threads are called upon, and demand for the second function is high, wherein there exists more demand for the second function than there are available threads, then the system""s performance may be constrained by the limited number of threads available for performing the second function. In other words, demands for work performed by the second function may be delayed because of the limited number of threads associated with the second function.
The foregoing scenario illustrates a situation where performance may be degraded even though there may be processing capacity available to meet the demand. Specifically, threads associated with the first function are idle while threads associated with the second function are fully utilized.
A method an apparatus that addresses the aforementioned problems, as well as other related problems, is therefore desirable.
In various embodiments, the invention provides reuse of a thread for executing application operations of different types. A thread operation class is defined as an abstract class from which concrete application operations can be instantiated. The application operation instances implement different functions for example. A separate thread is instantiated from a thread class. The various application operations can be scheduled for execution using the thread either by queuing the operations against the thread with the operating system or by starting the thread with one of the application operations and using an attach method to associate the other application operations with the thread.
In accordance with another embodiment of the invention, there is provided a computer program product that is configured to be operable to provide reuse of a thread for executing application operations of different types.
The above summary of the present invention is not intended to describe each disclosed embodiment of the present invention. The figures and detailed description that follow provide additional example embodiments and aspects of the present invention.